import { getValueWithLocalStorage } from '@/utils/authority';
const userInfo = getValueWithLocalStorage('userinfo');
import config from '../../config/web.config'

import { Tag } from 'antd';

 function shopLogo(){
  const headurl = userInfo.headurl
  if(headurl.indexOf('.png') == -1){
    return config.HttpUrl+'/file/pic/'+headurl+'.png'
  }else {
    return config.HttpUrl+'/file/pic/'+headurl
  }
}

function shopXCXLogo(){
    return config.HttpUrl+'/file/pic/shopcode_'+userInfo.tel+'.png'
}

function shopId() {
  return userInfo._id
}

function shopName() {
  return userInfo.shopname
}

function tel() {
  return userInfo.tel
}

function address(){
  return userInfo.address
}

function advtip(){
  return userInfo.advtip
}

function isVip(){
  return parseInt(userInfo.isVip) != 0
}

function vipLevel(){
  return parseInt(userInfo.viplevel)
}

function workTime(){
  return userInfo.workstarttime+'-'+userInfo.workendtime
}

function endTime(){
  return userInfo.endTime
}

function serviceTags(){
  return  userInfo.shopservice.map(item=>{
    return <Tag>{item.name}</Tag>
  })
}

function averageServiceAttitude(){
  return parseInt(userInfo.serviceAttitudeScore)/parseInt(userInfo.commentnum)
}

function averageServiceSpeedScore(){
  return parseInt(userInfo.serviceSpeedScore)/parseInt(userInfo.commentnum)
}

function favNum(){
  return parseInt(userInfo.favnum)
}

function commentNum(){
  return parseInt(userInfo.commentnum)
}

function xcxScanTotalNum(){
  return parseInt(userInfo.xcxScanTotalNum)
}

function xcxScanTodayNum(){
  return parseInt(userInfo.xcxScanTodayNum)
}

function shopPics() {
  var pics = userInfo.pics.split(',')
  return pics.map((item=>{
    if(item.length == 0){
      return ''
    }
    return config.HttpUrl+'/file/pic/'+item+'.png'
  }))
}

function parseIntVaild(num){
   if(num == undefined){
     return 0
   }
   if(num == null){
     return 0
   }
   if(num.length == 0){
    return 0
   }
   return parseInt(num)
}



module.exports = {
  shopLogo:shopLogo,
  shopName:shopName,
  address:address,
  isVip:isVip,
  vipLevel:vipLevel,
  workTime:workTime,
  endTime:endTime,
  services:serviceTags,
  shopXCXLogo:shopXCXLogo,
  averageServiceAttitude:averageServiceAttitude,
  averageServiceSpeedScore:averageServiceSpeedScore,
  favNum:favNum,
  commentNum:commentNum,
  xcxScanTodayNum:xcxScanTodayNum,
  xcxScanTotalNum:xcxScanTotalNum,
  shopId:shopId,
  shopPics:shopPics,
  advtip:advtip,
  tel:tel,
  parseIntVaild:parseIntVaild,
}


